package com.bbx.taxi.client.widget.Dailog;

import java.util.ArrayList;
import java.util.List;

import com.bbx.taxi.client.Util.IsActivityFinishUtils;
import com.bbx.taxi.official.R;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;

/**
 * 新用户优惠劵
 */
public class MyCityNotOpenedDailog extends Dialog {
	private LinearLayout layout_dailog;
	private boolean cancelable = true;
    private Context context;
    private boolean isFinish=false;
	public MyCityNotOpenedDailog(Context context) {
		super(context, R.style.Dialog_bocop2);
		this.context=context;
		init();
	}

	private void init() {
		View contentView = View.inflate(getContext(), R.layout.dailog_not_opened,
				null);
		layout_dailog=(LinearLayout)contentView.findViewById(R.id.layout_dialog);
		setContentView(contentView);
		this.setCancelable(false);
	}

	@Override
	public void show() {
		if(!IsActivityFinishUtils.isActivityFinish(context)){
		super.show();
		Animation a = AnimationUtils.loadAnimation(context, R.anim.dialog_in);
		layout_dailog.startAnimation(a);
		layout_dailog.setVisibility(View.VISIBLE);
		isFinish=false;
		}
	}

	@SuppressLint("NewApi")
	@Override
	public void dismiss() {
		if(!IsActivityFinishUtils.isActivityFinish(context)){
		if(isFinish)
		super.dismiss();
		Animation a = AnimationUtils.loadAnimation(context, R.anim.dialog_out);
		layout_dailog.startAnimation(a);
		a.setAnimationListener(new AnimationListener() {
			
			@Override
			public void onAnimationStart(Animation anim) {}
			
			@Override
			public void onAnimationRepeat(Animation anim) {}	
			@Override
			public void onAnimationEnd(Animation anim) {
				isFinish=true;
				dismiss();
			}
		});
		}

	}
	@Override
	public void setCancelable(boolean flag) {
		cancelable = flag;
		super.setCancelable(flag);
	}
}
